<?php
class User extends CI_Model{
	public function __construct(){
		parent::__construct();
        $this->load->database();
	}
	function get_userinfo($name,$word){
		$query = $this->db->get_where('oa_user',array('username'=>$name,'userpwd'=>md5($word)));
		return $query->row_array();
	}
	function insert_userinfo($arr){
		$this->db->insert('oa_user',$arr);
	}
	function get_all_userinfo(){
		$query = $this->db->get('oa_user');
		return $query->result_array();
	}
	function get_userpower($pid, $id){
		$this->db->select('*');
		$this->db->from('oa_departnode');
		$this->db->join('oa_node', 'oa_departnode.nodeid = oa_node.id');
		$this->db->where('oa_departnode.departid', $pid);
		
		$query = $this->db->get();
		
		$power = array();
		$content = '';
		if($query->result_array()){
			foreach($query->result_array() as $p){
				$power[] = strtolower($p['name']);
			}
			
			$content .= '<ul class="jstreen"><li class="level_one"><span title="1">部门管理<img src="' . base_url() . 'images/arrow_icon.png" /></span><ul class="jstreen1">';
			foreach($query->result_array() as $m){
				$content .= $m['pid'] == 1 && $m['ismenu'] ? '<li class="level_two" onclick="javascript:window.location=\'' . $m['linkurl'] . '\'"><span title="0">' . $m['notes'] . '<img src="' . base_url() . 'images/arrow_icon.png"/></span></li>' : '';
			}
			$content .= '</ul></li></ul>';
			
			$content .= '<ul class="jstreen"><li class="level_one"><span title="7">用户管理<img src="' . base_url() . 'images/arrow_icon.png" /></span><ul class="jstreen1">';
			foreach($query->result_array() as $m){
				$content .= $m['pid'] == 7 && $m['ismenu'] ? '<li class="level_two" onclick="javascript:window.location=\'' . $m['linkurl'] . '\'"><span title="0">' . $m['notes'] . '<img src="' . base_url() . 'images/arrow_icon.png"/></span></li>' : '';
			}
			$content .= '</ul></li></ul>';
			
			$content .= '<ul class="jstreen"><li class="level_one"><span title="12">公文管理<img src="' . base_url() . 'images/arrow_icon.png" /></span><ul class="jstreen1">';
			foreach($query->result_array() as $m){
				$content .= $m['pid'] == 12 && $m['ismenu'] ? '<li class="level_two" onclick="javascript:window.location=\'' . $m['linkurl'] . '\'"><span title="0">' . $m['notes'] . '<img src="' . base_url() . 'images/arrow_icon.png"/></span></li>' : '';
			}
			$content .= '</ul></li></ul>';
			
			@unlink('./application/cache/' . $id . '.txt');
			file_put_contents('./application/cache/' . $id . '.txt', $content);
		}else{
			$content .= '<ul class="jstreen"><li class="level_one"><span title="1">部门管理<img src="' . base_url() . 'images/arrow_icon.png" /></span><ul class="jstreen1"></ul></li></ul>';
			$content .= '<ul class="jstreen"><li class="level_one"><span title="7">用户管理<img src="' . base_url() . 'images/arrow_icon.png" /></span><ul class="jstreen1"></ul></li></ul>';
			$content .= '<ul class="jstreen"><li class="level_one"><span title="12">公文管理<img src="' . base_url() . 'images/arrow_icon.png" /></span><ul class="jstreen1"></ul></li></ul>';
			@unlink('./application/cache/' . $id . '.txt');
			file_put_contents('./application/cache/' . $id . '.txt', $content);
		}
		
		return $power;
	}

}
?>